/**
 * 
 */
package com.cyou.qb.common.domain.vo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.springframework.util.Assert;

import com.cyou.qb.common.domain.Award;
import com.cyou.qb.common.domain.JiuGongGeEx;

/**
 * @author zoudongchao
 *
 */
public class DrawAward {
	private int id;
	private String awardName;
	private String awardType;
	private int winnerId;
	
	public DrawAward(){
	}
	
	public DrawAward(Award award, int winnerId) {
		this.id = award.getId();
		this.awardName = award.getName();
		this.awardType = award.getType();
		this.winnerId = winnerId;
	}
	
	public DrawAward(int id, String name, String type, int winnerId) {
		this.id = id;
		this.awardName = name;
		this.awardType = type;
		this.winnerId = winnerId;
	}
	
	/**
	 * 定位奖品在九宫格中的配置
	 * 	如果奖品不存在，就随机取一个谢谢参与
	 * @param jiuGongGeExList
	 * @param award
	 * @return
	 */
	public static JiuGongGeEx position(List<JiuGongGeEx> jiuGongGeExList,DrawAward award){
		Assert.notEmpty(jiuGongGeExList);
		List<JiuGongGeEx> emptyPosition = new ArrayList<JiuGongGeEx>(5);
		for (JiuGongGeEx ex : jiuGongGeExList) {
			if(award!=null&&ex.getAwardId()==award.id)
				return ex;
			if(ex.getAwardId()==-1){
				emptyPosition.add(ex);
			}
		}
		Assert.notEmpty(emptyPosition,"不能8个都是奖品");
		Random random = new Random();
		int idx = random.nextInt(emptyPosition.size());
		return emptyPosition.get(idx);
	}
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getAwardName() {
		return awardName;
	}
	public void setAwardName(String awardName) {
		this.awardName = awardName;
	}
	public String getAwardType() {
		return awardType;
	}
	public void setAwardType(String awardType) {
		this.awardType = awardType;
	}
	
	
	public static void main(String[] args) {
		Random random = new Random();
		for (int i = 0; i < 20; i++) {
			System.out.println(random.nextInt(5));
			
		}
	}

	public int getWinnerId() {
		return winnerId;
	}

	public void setWinnerId(int winnerId) {
		this.winnerId = winnerId;
	}
	
}
